package com.kgc.ssm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kgc.ssm.entity.EnquireDetail;
import com.kgc.ssm.entity.EnquireDetailExample;
import com.kgc.ssm.entity.dto.Result;
import com.kgc.ssm.entity.dto.SearchParam;
import com.kgc.ssm.mapper.EnquireDetailMapper;
import com.kgc.ssm.service.EnquireDetailService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class EnquireDetailServiceImpl implements EnquireDetailService {
@Resource
    private  EnquireDetailMapper enquireDetailMapper;
    @Override
    public Result<List<EnquireDetail>> findPage(SearchParam param) {
        PageHelper.startPage(param.getPageNum(),param.getPageSize());
        EnquireDetailExample example=new EnquireDetailExample();
        EnquireDetailExample.Criteria criteria=example.createCriteria();
        if(Strings.isNotEmpty(param.getMaterialCode())){
            criteria.andMaterialCodeLike("%"+param.getMaterialCode()+"%");
        }
        if(Strings.isNotEmpty(param.getMaterialName())){
            criteria.andMaterialNameLike("%"+param.getMaterialName()+"%");

        }
        if(Strings.isNotEmpty(param.getStatus())){
            criteria.andStatusEqualTo(param.getStatus());
        }
        Page<EnquireDetail> page=(Page<EnquireDetail>) enquireDetailMapper.selectByExample(example);

        return   new Result<>("查询成功",200,page.getResult(),page.getTotal());
    }
}
